/*
 * Quat4.h
 *
 *  Created on: 29 août 2010
 *      Author: seeme
 *      des quaternions
 *      On peut les normalizer et faire leur
 *      produit (==cumuler les rotations)
 */

#ifndef QUAT4_H_
#define QUAT4_H_

#include <ostream>
#include <cmath>

#include "Vect4.h"
#include "Vect3f.h"
#include "Matrix4.h"

class Quat4f {
public:

    Quat4f();
    Quat4f(float w, float x, float y, float z);
    Quat4f(float w, Vector3f<float> v);
    Quat4f(const Quat4f& q);

    Quat4f& operator=(const Quat4f& q);
    Quat4f operator+(const Quat4f& q) const;
    Quat4f operator-(const Quat4f& q) const;
    Quat4f operator/(const Quat4f& q) const;
    Quat4f operator/(float scalar) const;
    Quat4f& operator/=(float scalar);
    Quat4f operator*(const Quat4f& q) const;



    bool operator==(const Quat4f& q) const;

    float norm() const;
    float normSquared() const;
    void normalize();
    void conjugate();
    void inverse();
    Matrix4<float> matrix4();

    static inline Quat4f fromAxisAngle(const Vector3f<float> &axis, float angle) {
        return Quat4f(cosf(angle/2), axis*sinf(angle/2));
    }

    friend std::ostream &operator<<(std::ostream &o, const Quat4f& q);
  //  friend QDebug operator<<(QDebug qdbg, const Quat4f& q);

    float w;
    Vector3f<float> v;
};

#endif /* QUAT4_H_ */
